package com.woniuxy.lrz.carlproject.controller;

import com.woniuxy.lrz.carlproject.common.Result;
import com.woniuxy.lrz.carlproject.controller.form.userform.AddShopcarForm;
import com.woniuxy.lrz.carlproject.controller.form.userform.ChangeShopcarForm;
import com.woniuxy.lrz.carlproject.model.Shopcar;
import com.woniuxy.lrz.carlproject.service.ShopcarService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author lrz
 * @since 2022-10-04
 */
@RestController
@RequestMapping("/shopcar")
public class ShopcarController {
    @Resource
    private ShopcarService shopcarService;
    //新增购物车
    @PostMapping("/addShopcar")
    public Result addShopcar(@RequestBody AddShopcarForm addShopcarForm){
        shopcarService.addShopcar(addShopcarForm);
        return Result.success("新增购物车成功");
    }
    //查询购物车
    @GetMapping("/getShopcar")
    public Result getShopcar(){
        List<Shopcar> shopcar = shopcarService.getShopcar();
        return Result.success(shopcar);
    }
    //修改购物车
    @PutMapping("/changeNum")
    public Result changeNum(@RequestBody ChangeShopcarForm changeShopcarForm){
        shopcarService.changeNum(changeShopcarForm);
        return Result.success("修改成功");
    }
    //移除购物车
    @DeleteMapping("/deleteGood")
    public Result deleteGood(Integer shopcarId){
        shopcarService.deleteGood(shopcarId);
        return Result.success("删除成功");
    }
}
